<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!-- <!DOCTYPE html> -->
<html lang="en">
<head>
<meta charset="UTF-8">
<title>软件分享系统</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery-3.3.1.js"></script>
<script src="js/bootstrap.min.js"></script>
<style>
th {
	text-align: center !important;
}

.r {
	float: right;
	margin-right: 20px;
}

.tm {
	margin-left: 3px;
}

.w { width: 150px;margin:0 25px;}
</style>
</head>
<body class="bg-success">

	<div class="row">
		<div class="col-md-2"></div>
		<div class="col-md-10"><h1 style="letter-spacing:5px;">欢迎来到软件分享系统</h1></div>
	</div>
	<div class="row">
		<div class="col-md-2"></div>
		<div class="col-md-8">
			<!-- 导航 -->
			<nav class="navbar navbar-default" role="navigation">
				<div class="container-fluid">
					<div class="navbar-header">
						<button type="button" class="navbar-toggle" data-toggle="collapse"
							data-target="#example-navbar-collapse">
							<span class="sr-only">切换导航</span> <span class="icon-bar"></span>
							<span class="icon-bar"></span> <span class="icon-bar"></span>
						</button>
						<a class="navbar-brand" href="#">软件分享系统</a>
					</div>
					<div class="collapse navbar-collapse" id="example-navbar-collapse">
						<ul class="nav navbar-nav">
							<li class="active"><a href="/rjfxsys/user?method=getUsers">用户信息</a></li>
							<li ><a href="/rjfxsys/software?method=getSoftwares">软件信息</a></li>
							<li ><a href="/rjfxsys/comment?method=getComments">评论信息</a></li>

						</ul>
						<ul class="nav navbar-nav navbar-right">
							<li class="dropdown"><a href="#" class="dropdown-toggle">${username}</a></li>
							<li class="dropdown"><a href="/rjfxsys/registration?method=logout"
								class="dropdown-toggle"> 退出 </a></li>
						</ul>
					</div>
				</div>
			</nav>

		</div>
		<div class="col-md-2"></div>
	</div>


	<div class="row">
		<div class="col-md-3"></div>
		<div class="col-md-6 text-center">
            
			<div class="form-horizontal">
			    <input id="id" type="hidden">
				<div class="form-group ">
					<label class="col-sm-2 control-label">用户名</label>
					<div class="col-sm-10">
						<input id="id2" type="hidden"> <input class="form-control"
															  id="username" name="username" type="text" placeholder="该输入用户名">
					</div>
				</div>
				<div class="form-group ">
					<label class="col-sm-2 control-label">密码</label>
					<div class="col-sm-10">
						<input class="form-control" id="password" name="password"
							   type="text" placeholder="该输入密码">

					</div>
				</div>
				<div class="form-group ">
					<label class="col-sm-2 control-label">姓名</label>
					<div class="col-sm-10">
						<input class="form-control" id="realname" name="realname"
							   type="text" placeholder="该输入姓名">

					</div>
				</div>
				<div class="form-group ">
					<label class="col-sm-2 control-label">性别</label>
					<div class="col-sm-10">
						<input class="form-control" id="sex" name="sex"
							   type="text" placeholder="该输入性别">

					</div>
				</div>
				<div class="form-group ">
					<label class="col-sm-2 control-label">手机号码</label>
					<div class="col-sm-10">
						<input class="form-control" id="phone" name="phone"
							   type="text" placeholder="该输入手机号码">

					</div>
				</div>
				<div class="form-group ">
					<label class="col-sm-2 control-label">用户类型</label>
					<div class="col-sm-10">
						<select id="userType" name="userType" class="form-control">
							<option value="">该选择用户类型</option>
							<option value="管理员">管理员</option>
							<option value="普通用户">普通用户</option>
						</select>
					</div>
				</div>

			</div>

			<button type="button" class="btn btn-primary w" onclick="update()">保存</button>
              <a href="/rjfxsys/user?method=getUsers"><button type="button" class="btn btn-primary w">返回</button></a>

		</div>
		<div class="col-md-4"></div>
	</div>



</body>
<script>
	//渲染修改页面
	upd();
	function upd() {
		console.log(666)
		var ID = location.search.split("=")[1];
		console.log(ID)
		$.ajax({
			url : "/rjfxsys/user?method=getUser",
			data : {
				id : ID
			},
			type : "POST",
			success : function(data) {
				console.log(data);
				data = JSON.parse(data);
				if (data) {
					$("#id").val(data.id);
					$("#username").val(data.username);
					$("#password").val(data.password);
					$("#realname").val(data.realname);
					$("#sex").val(data.sex);
					$("#phone").val(data.phone);
					$("#userType").val(data.userType);

				} else {
					alert('查询失败！'
							+ (data.handle != 'undefind' ? data.handle : ""));
				}
			}
		})
	}

	//修改数据
	function update() {
		var id = $("#id").val();
		var username = $("#username").val();
		var password = $("#password").val();
		var realname = $("#realname").val();
		var sex = $("#sex").val();
		var phone = $("#phone").val();
		var userType = $("#userType").val();

		console.log();
		$.ajax({
			url : "/rjfxsys/user?method=updateUser",
			data : {
				id : id,
				username : username,
				password : password,
				realname : realname,
				sex : sex,
				phone : phone,
				userType : userType
			},
			type : "POST",
			success : function(data) {
				console.log(data);
				data = JSON.parse(data);
				if (data.msg == "ok") {
					alert("修改成功！");
					location.href = "/rjfxsys/user?method=getUsers";
				} else {
					alert('修改失败！'
							+ (data.handle != 'undefind' ? data.handle : ""));
				}
			}
		})
	}
</script>
</html>